<template>
  <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="50%"
      append-to-body
      :before-close="handleClose">
    <avue-form ref="form" v-model="formModel" @submit="submitForm" :option="formOption">
      <template slot="menuForm">
        <el-button @click="dialogVisible=false">取消</el-button>
      </template>
    </avue-form>
  </el-dialog>
</template>

<script>
import userOption from "@/option/sys/userOption";
import modelOption from "@/option/start/activiti/modelOption";
import modelApi from "@/api/start/activiti/modelApi";
import userApi from "@/api/sys/userApi";
import optionUtils from "@/option/optionUtils";

export default {
  name: "startConfigDialog",
  computed: {
    formOption() {
      return {
        submitText: "确定",
        column: [
          {
            label: '流程',
            span: 24,
            prop: 'modelId',
            type: "table",
            props: {
              label: 'name',
              value: 'id'
            },
            children: modelOption(),
            onLoad: (onLoadParams, callback) => {
              onLoadParams.pageDefinition = modelApi.list
              onLoadParams.valueDefinition = modelApi.getById
              onLoadParams.option = modelOption;
              optionUtils.tableOnLoad(onLoadParams, callback)
            },
          },
          {
            label: '启动人',
            span: 24,
            prop: 'userId',
            type: "table",
            props: {
              label: 'userName',
              value: 'id'
            },
            row: true,
            children: userOption(),
            onLoad: (onLoadParams, callback) =>{
              onLoadParams.pageDefinition = userApi.list
              onLoadParams.valueDefinition = userApi.getUserInfo
              onLoadParams.option = userOption;
              optionUtils.tableOnLoad(onLoadParams,callback)
            },
            formatter: (row) => {
              if (!row) return;
              if (row.nickName) {
                return row.nickName;
              } else if (row.realName) {
                return row.realName
              }
              return row.userName;
            }
          },
        ]
      }
    }
  },
  data() {
    return {
      dialogVisible: false,
      formModel: {}
    }
  }
  ,
  methods: {
    show() {
      this.dialogVisible = true
    },
    handleEmpty() {
      this.$refs.form.resetForm();
    },
    handleClose() {
      this.dialogVisible=false
      this.handleEmpty();
    },
    submitForm(model, done) {
      done();
      this.handleClose();
      this.$emit("refresh")
      let routerJump = this.$router.resolve({path: `/activiti/start/${model.modelId}?userId=${model.userId}`})
      window.open(routerJump.href, '_blank');
    }
  }
}
</script>

<style scoped>

</style>
